var xmlHttp; 
    function GetXmlHttpObject(){ 
    　　if (window.XMLHttpRequest){ 
    　　　　xmlhttp=new XMLHttpRequest(); 
    　　}else{
    　　　　xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    　　} 
    　　return xmlhttp; 
    }
    
    //请求区域列表的函数
    function getAeraGet(){ 
    　　xmlHttp=GetXmlHttpObject(); 
    　　if (xmlHttp==null){ 
    　　　　alert('浏览器不支持'); 
    　　　　return; 
    　　} 
    　　var url='http://test.eshangtech.com:6060/HighWay/Handler/handler_ajax.ashx?action_type=getTotalServerPart'; 
    　　xmlHttp.open("GET",url,true); 
    　　xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
        xmlhttp.send(); 
        xmlHttp.onreadystatechange=getAreaOkPost;
    }
    //请求区域公司列表的函数
    function getShopsGet(i){ 
    　　xmlHttp=GetXmlHttpObject(); 
    　　if (xmlHttp==null){ 
    　　　　alert('浏览器不支持'); 
    　　　　return; 
    　　} 
    　　var url='http://test.eshangtech.com:6060/HighWay/Handler/handler_ajax.ashx?action_type=getServerPartShop&action_data='+i; 
    　　xmlHttp.open("GET",url,true); 
    　　xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
        xmlhttp.send(); 
        xmlHttp.onreadystatechange=getShopsOkPost; 
    }
    //请求公司的结账数据列表
    function getMoneyGet(i){ 
    　　xmlHttp=GetXmlHttpObject(); 
    　　if (xmlHttp==null){ 
    　　　　alert('浏览器不支持'); 
    　　　　return; 
    　　} 
    　　var url='http://test.eshangtech.com:6060/HighWay/Handler/handler_ajax.ashx?action_type=getServerPartEndaccount&action_data='+i; 
    　　xmlHttp.open("GET",url,true); 
    　　xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
        xmlhttp.send(); 
        xmlHttp.onreadystatechange=getMoneyOkPost; 
    }
    //请求区域成功的回调函数
    function getAreaOkPost(){ 
        if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3){ 
        // 本地提示：加载中/处理中 
        } 
        if (xmlHttp.readyState==4 && xmlHttp.status==200){ 
    
            var area = JSON.parse(xmlHttp.responseText)
            var ServerIdArr = area.SERVERPARTObject
            // console.log(ServerIdArr)
            $.each(ServerIdArr,function(n,v){
                $('.area').append('<option value="'+v.SERVERPART_ID+'">'+v.SERVERPART_NAME+'</option>')
            })
            var areaId = $('.area').val()
            console.log('过')
            var areaName = $(".area").find("option:selected").text();
            $('.area_name').text(areaName)
            // console.log(areaId)
            getShopsGet(areaId)
        } 
    } 
    //请求区域公司的成功函数
    function getShopsOkPost(){ 
        if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3){ 
        // 本地提示：加载中/处理中 
        } 
        if (xmlHttp.readyState==4 && xmlHttp.status==200){ 
            var shops = JSON.parse(xmlHttp.responseText)
            var shopArr = shops.ServerPartShopObject
            console.log(shopArr)
            $('.shops').html('')
            $.each(shopArr,function(n,v){
                $('.shops').append('<option value="'+v.SERVERPARTSHOP_ID+'">'+v.SHOPNAME+'</option>')
            })
            var shopId = $('.shops').val()
            var shopName = $(".shops").find("option:selected").text();
            console.log(shopName)
            $('.shop_name').text(shopName)
            console.log(shopId)
            getMoneyGet(shopId)
        } 
    }
    //请求公司结账数据成功的回调函数
    function getMoneyOkPost(){
        if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3){ 
        // 本地提示：加载中/处理中 
        } 
        if (xmlHttp.readyState==4 && xmlHttp.status==200){ 
            console.log('钱')
            var money = JSON.parse(xmlHttp.responseText)
            var moneyArr = money.EndaccountObject
            kedan(moneyArr)
            xssl(moneyArr)
            xsje(moneyArr)
            pje(moneyArr)
            jj(moneyArr)
            if(moneyArr.length == 0){
                $('.money_list').text('没有账单')
            }else{
                var listHtml = ''
                $.each(moneyArr,function(n,v){
                    var junjia = (v.TOTALSELLAMOUNT/v.TICKETCOUNT).toFixed(2)
                    listHtml += `
                                <tr>
                                    <td>`+v.TICKETCOUNT+`</td>
                                    <td>`+v.TOTALCOUNT+`</td>
                                    <td>¥`+v.TOTALSELLAMOUNT+`</td>
                                    <td>¥`+v.CASHPAY+`</td>
                                    <td>`+v.MOBILEPAYMENT+`</td>
                                    <td>¥`+junjia+`</td>
                                    <td>`+v.ENDACCOUNT_DATE+`</td>
                                </tr>
                                `
                })
                $('.tbody').html(listHtml)
            }
        } 
    }
    getAeraGet()
    function AreaChange(e){
        var AreaId = $('.area').val()
        getShopsGet(AreaId)
        var areaName = $(".area").find("option:selected").text();
        $('.area_name').text(areaName)
    }
    function ShopsChange(e){
        var ShopId = $('.shops').val()
        getMoneyGet(ShopId)
        console.log(ShopId)
    }


    // heightchart



    function kedan(m){
        var data = [
            {name:'', value:0},
        ]
        console.log(m)
        var mans = []
        $.each(m,function(n,v){
            data.push({
                name:v.ENDACCOUNT_DATE.split(' ')[1],
                value:v.TICKETCOUNT*1
            })
        })
        console.log(mans)
        console.log(data)
        new sChart('kedan', 'line', data, {
            title: '客单数量折线图',
            bgColor: 'gray',
            titleColor: '#ffffff',
            fillColor: '#ffffff',
            axisColor: '#eeeeee',
            contentColor: '#bbbbbb'
        });
        options = {
            padding: 0,                    
            yEqual: 10,                    
            bgColor: '#ffffff',            
            fillColor: '#1E9FFF',          
            axisColor: '#666666',          
            contentColor: '#eeeeee',       
            titleColor: '#000000',         
            titlePosition: 'top'           
        }
    }
    function xssl(m){
        var data = [
            {name:'', value:0},
        ]
        console.log(m)
        var mans = []
        $.each(m,function(n,v){
            data.push({
                name:v.ENDACCOUNT_DATE.split(' ')[1],
                value:v.TOTALCOUNT*1
            })
        })
        console.log(mans)
        console.log(data)
        new sChart('xssl', 'line', data, {
            title: '销售数量折线图',
            bgColor: 'gray',
            titleColor: '#ffffff',
            fillColor: '#ffffff',
            axisColor: '#eeeeee',
            contentColor: '#bbbbbb'
        });
        options = {
            padding: 0,                    
            yEqual: 10,                    
            bgColor: '#ffffff',           
            fillColor: '#1E9FFF',         
            axisColor: '#666666',           
            contentColor: '#eeeeee',        
            titleColor: '#000000',        
            titlePosition: 'top'          
        }
    }
    function xsje(m){
        var data = [
            {name:'', value:0},
        ]
        console.log(m)
        var mans = []
        $.each(m,function(n,v){
            data.push({
                name:v.ENDACCOUNT_DATE.split(' ')[1],
                value:v.TOTALSELLAMOUNT*1
            })
        })
        console.log(mans)
        console.log(data)
        new sChart('xsje', 'line', data, {
            title: '销售金额折线图',
            bgColor: 'gray',
            titleColor: '#ffffff',
            fillColor: '#ffffff',
            axisColor: '#eeeeee',
            contentColor: '#bbbbbb'
        });
        options = {
            padding: 0,                    
            yEqual: 10,                    
            bgColor: '#ffffff',          
            fillColor: '#1E9FFF',        
            axisColor: '#666666',       
            contentColor: '#eeeeee',    
            titleColor: '#000000',       
            titlePosition: 'top'            
        }
    }
    function pje(m){
        var data = [
            {name:'', value:0},
        ]
        console.log(m)
        var mans = []
        $.each(m,function(n,v){
            data.push({
                name:v.ENDACCOUNT_DATE.split(' ')[1],
                value:v.MOBILEPAYMENT*1
            })
        })
        console.log(mans)
        console.log(data)
        new sChart('pje', 'line', data, {
            title: '手机支付金额折线图',
            bgColor: 'gray',
            titleColor: '#ffffff',
            fillColor: '#ffffff',
            axisColor: '#eeeeee',
            contentColor: '#bbbbbb'
        });
        options = {
            padding: 0,                    
            yEqual: 10,                     
            bgColor: '#ffffff',             
            fillColor: '#1E9FFF',           
            axisColor: '#666666',           
            contentColor: '#eeeeee',        
            titleColor: '#000000',          
            titlePosition: 'top'            
        }
    }
    function jj(m){
        var data = [
            {name:'', value:0},
        ]
        console.log(m)
        var mans = []
        $.each(m,function(n,v){
            data.push({
                name:v.ENDACCOUNT_DATE.split(' ')[1],
                value:((v.TOTALSELLAMOUNT*1)/(v.TICKETCOUNT*1)).toFixed(2)
            })
        })
        console.log(mans)
        console.log(data)
        new sChart('jj', 'line', data, {
            title: '客单均价折线图',
            bgColor: 'gray',
            titleColor: '#ffffff',
            fillColor: '#ffffff',
            axisColor: '#eeeeee',
            contentColor: '#bbbbbb'
        });
        options = {
            padding: 0,                    
            yEqual: 10,                      
            bgColor: '#ffffff',             
            fillColor: '#1E9FFF',           
            axisColor: '#666666',           
            contentColor: '#eeeeee',        
            titleColor: '#000000',          
            titlePosition: 'top'            
        }
    }
    $('#kedan').hide()
    $('#xssl').hide()
    $('#xsje').hide()
    $('#pje').hide()
    $('#jj').show()
    function kedanclick(){
        $('#kedan').show()
        $('#xssl').hide()
        $('#xsje').hide()
        $('#pje').hide()
        $('#jj').hide()
    }
    function xsslclick(){
        $('#kedan').hide()
        $('#xssl').show()
        $('#xsje').hide()
        $('#pje').hide()
        $('#jj').hide()
    }
    function xsjeclick(){
        $('#kedan').hide()
        $('#xssl').hide()
        $('#xsje').show()
        $('#pje').hide()
        $('#jj').hide()
    }
    function pjeclick(){
        $('#kedan').hide()
        $('#xssl').hide()
        $('#xsje').hide()
        $('#pje').show()
        $('#jj').hide()
    }
    function jjclick(){
        $('#kedan').hide()
        $('#xssl').hide()
        $('#xsje').hide()
        $('#pje').hide()
        $('#jj').show()
    }
